// UdpServer.cc
#include "UdpServer.hpp"
#include <vector>
#include <memory>
#include <cstdio>

Log log;

void Usage(std::string proc)
{
    std::cout << "\n\rUsage: " << proc << " port[1024+]\n" << std::endl;
}

std::string Handler(const std::string &info, const std::string &clientip, uint16_t clientport)
{
    std::cout << "[" << clientip << ":" << clientport << "]# " << info << std::endl;
    
    std::string res = "Server get a message: ";
    res += info;
    // std::cout << res << std::endl;

    return res;
}

// 命令行启动服务器，自行输入端口号：./udpserver port
int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        Usage(argv[0]);
        exit(0);
    }
    uint16_t port = std::stoi(argv[1]);

    std::unique_ptr<UdpServer> svr(new UdpServer(port));
    svr->Init();
    svr->Run(Handler);

    return 0;
}